package com.ziyun.pop.web.modules.erpCustomerServieceUser.controller;

import java.util.Arrays;
import java.util.Map;

import com.ziyun.pop.common.utils.UserUtils;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ziyun.pop.modules.erpCustomerServieceUser.entity.ErpCustomerServieceUserEntity;
import com.ziyun.pop.modules.erpCustomerServieceUser.service.ErpCustomerServieceUserService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 跟单员业务员表
 *
 * @author llc
 * @email 787254039@qq.com
 * @date 2018-11-21 09:43:56
 */
@RestController
@RequestMapping("erpCustomerServieceUser/erpcustomerservieceuser")
public class ErpCustomerServieceUserController {
    @Autowired
    private ErpCustomerServieceUserService erpCustomerServieceUserService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("erpCustomerServieceUser:erpcustomerservieceuser:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = erpCustomerServieceUserService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("erpCustomerServieceUser:erpcustomerservieceuser:info")
    public R info(@PathVariable("id") Integer id){
        ErpCustomerServieceUserEntity erpCustomerServieceUser = erpCustomerServieceUserService.getById(id);

        return R.ok().put("erpCustomerServieceUser", erpCustomerServieceUser);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("erpCustomerServieceUser:erpcustomerservieceuser:save")
    public R save(@RequestBody ErpCustomerServieceUserEntity erpCustomerServieceUser){
        erpCustomerServieceUser.setType(3);
        erpCustomerServieceUser.setSellerId(UserUtils.getCurentUser().getSellerId().intValue());
        erpCustomerServieceUserService.save(erpCustomerServieceUser);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("erpCustomerServieceUser:erpcustomerservieceuser:update")
    public R update(@RequestBody ErpCustomerServieceUserEntity erpCustomerServieceUser){
        ValidatorUtils.validateEntity(erpCustomerServieceUser);
        erpCustomerServieceUserService.updateById(erpCustomerServieceUser);//全部更新
        
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/updateDisplay/{id}")
    public R updateDisplay(@PathVariable("id") Integer id){
        ErpCustomerServieceUserEntity erpCustomerServieceUserEntity = erpCustomerServieceUserService.getById(id);
        erpCustomerServieceUserEntity.setDelFlag(!erpCustomerServieceUserEntity.getDelFlag());
        erpCustomerServieceUserService.updateById(erpCustomerServieceUserEntity);//全部更新
        return R.ok();
    }


    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("erpCustomerServieceUser:erpcustomerservieceuser:delete")
    public R delete(@RequestBody Integer[] ids){
        erpCustomerServieceUserService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
